package cn.tedu.egweibo.base.execption;

import cn.tedu.egweibo.base.respont.JsonResult;
import cn.tedu.egweibo.base.respont.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.Jar;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolationException;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult handleConstraintViolationException(ConstraintViolationException ex){
        String data = ex.getMessage().split(":")[1].trim();
        log.debug("handleConstraintViolationException{}", data);
        return new JsonResult(StatusCode.VALIDATED_ERROR,data);
    }
}
